﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Quản lí bộ test</title>
</head>
<body>
<?php 
require_once("../include/db_info.inc.php"); 
require_once("admin-header.php");
require_once("../maincore.php");
if (!defined("THNOJ")) die("Outside of the site");
if(!isset($_GET['id'])) die("Quay lại");
$pid=intval($_GET['id']);

$sql="SELECT * FROM `ctd_test` WHERE `problem`=".$pid." limit 20";
$result=mysql_query($sql);
$basedir=$OJ_DATA."/$pid";
if(!file_exists($basedir)) {
	mkdir($basedir); 
} else {
	$files = glob($basedir.'/*.*'); 
	foreach($files as $file){ 
	  if(is_file($file))
		unlink($file); 
	}

}
while ($row=mysql_fetch_array($result)) {
	$fp=fopen($basedir."/".$row['id'].".in","w");
	fputs($fp,$row['input']);
	fclose($fp);
	$fp=fopen($basedir."/".$row['id'].".out","w");
	fputs($fp,$row['output']);
	fclose($fp);
}
echo "Đã xong!";
require_once("../oj-footer.php");
redirect("problem_tests.php?pid=$pid",3);
?>


</body>
</html>

